﻿/******************************************************************** 
 * Cerebrum Embedded System Design Automation Framework
 * Copyright (C) 2010  The Pennsylvania State University
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ********************************************************************/
/*********************************************************************************************************** 
 * FalconFileRoutines.cs
 * Name: Matthew Cotter
 * Date: 12 Aug 2010 
 * Description: Library to handle common file routines used across all Falcon/Cerebrum Tools.
 * Notes:
 *     
 * History: 
 * >> (12 Aug 2010) Matthew Cotter: Source file created -- Initial version.
 ***********************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace FalconGlobal
{
    /// <summary>
    /// Static class to handle common File Access routines used across all Falcon/Cerebrum tools.
    /// </summary>
    public static class FalconFileRoutines
    {
        /// <summary>
        /// Writes the standard Cerebrum Tool disclaimer, using "//" as a comment prefix on each line.
        /// </summary>
        /// <param name="writer">An open StreamWriter object to which the disclaimer should be written.</param>
        public static void WriteCerebrumDisclaimer(StreamWriter writer)
        {
            WriteCerebrumDisclaimer(writer, "#");
        }

        /// <summary>
        /// Writes the standard Cerebrum Tool disclaimer, using the specified string as a comment prefix on each line.
        /// </summary>
        /// <param name="writer">An open StreamWriter object to which the disclaimer should be written.</param>
        /// <param name="CommentString">The string to prefix each line with, indicating that it is to be interpreted as a comment.</param>
        public static void WriteCerebrumDisclaimer(StreamWriter writer, string CommentString)
        {
            writer.Write(String.Format("{0} \n", CommentString));
            writer.Write(String.Format("{0} This file was automatically generated by the Cerebrum Design Framework.\n", CommentString));
            writer.Write(String.Format("{0} \n", CommentString));
            writer.Write(String.Format("{0} Generated at {1} on {2}\n", CommentString, DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()));
            writer.Write(String.Format("{0} \n", CommentString));
            writer.Write(String.Format("{0} Any modifications made to this file may be lost.\n", CommentString));
            writer.Write(String.Format("{0} \n", CommentString));
        }

        /// <summary>
        /// Appends an XML Comment to the specified XmlNode (typically the root node)
        /// </summary>
        /// <param name="xRootNode">The XmlNode to which the comment should be appended (typically the root node).</param>
        public static void WriteCerebrumDisclaimerXml(XmlNode xRootNode)
        {
            string Comment = String.Format("This file was automatically generated or modified by the Cerebrum Design Framework at {0} on {1}.", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
            XmlNode xCommentNode = xRootNode.OwnerDocument.CreateComment(Comment);
            xRootNode.AppendChild(xCommentNode);
        }
    }
}
